package model.components.nodes.node;

import java.util.ArrayList;
import java.util.List;

public class PhysicalNode extends Node
{	
	private int availableCpu;
	public int getAvailableCpu(){ return availableCpu; }
	public void setAvailableCpu( int availableCpu ){ this.availableCpu = availableCpu; }

	private int availableMemory;
	public int getAvailableMemory(){ return availableMemory; }
	public void setAvailableMemory( int availableMemory ){ this.availableMemory = availableMemory; }
	
	protected int availableDiskSpace;
	public int getAvailableDiskSpace(){ return 0; }	
	public void setAvailableDiskSpace( int availableDiskSpace ){ }
	
	private int maxVirtualNodesNumber;
	public int getMaxVirtualNodesNumber(){ return maxVirtualNodesNumber; }
	public void setMaxVirtualNodesNumber( int maxVirtualNodesNumber ){ this.maxVirtualNodesNumber = maxVirtualNodesNumber; }
	
	private int availableVirtualNodesNumber;
	public int getAvailableVirtualNodesNumber(){ return availableVirtualNodesNumber; }
	public void setAvailableVirtualNodesNumber( int availableVirtualNodesNumber ){ this.availableVirtualNodesNumber = availableVirtualNodesNumber; }
	
	private List< VirtualNode > virtualNodes;
	public List< VirtualNode > getVirtualNodes(){ return virtualNodes; }
	public void setVirtualNodes( List< VirtualNode > virtualNodes ){ this.virtualNodes = virtualNodes; }
	
	public PhysicalNode( String networkName, String namePrefix, int number, String type, String operatingSystem, String virtualEnvironment, int cpu, int memory, int maxVirtualNodesNumber, String greyIcon, String greenIcon, String yellowIcon, String redIcon )
	{
		super( networkName, namePrefix, number, type, operatingSystem, virtualEnvironment, cpu, memory, greyIcon, greenIcon, yellowIcon, redIcon );

		this.setAvailableCpu( cpu );
		this.setAvailableMemory( memory );
		this.setMaxVirtualNodesNumber( maxVirtualNodesNumber );
		this.setAvailableVirtualNodesNumber( maxVirtualNodesNumber );
		this.setVirtualNodes( new ArrayList< VirtualNode >() );
	}
	
	@Override
	public PhysicalNode getCopy()
	{
		return null;
	}
	
	public void add( VirtualNode virtualNode )
	{
		this.getVirtualNodes().add( virtualNode );
	}
	
	public void remove( VirtualNode virtualNodeToRemove )
	{
		int virtualNodeIndex = -1;
		
		for( VirtualNode virtualNode: this.getVirtualNodes() )
			if( virtualNode.equals( virtualNodeToRemove ) )
				virtualNodeIndex = this.getVirtualNodes().indexOf( virtualNode );
		
		if( virtualNodeIndex != -1 )
			this.getVirtualNodes().remove( virtualNodeIndex );
	}
	
}
